﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using YDModel;
using YDServices.Comm;

namespace YDServices
{
    public class RolePermissionService : BaseService
    {
        /// <summary>
        /// 获取权限列表
        /// </summary>
        public List<T_Permission> getTreeData(long roleID)
        { 
             try
            {
                using (YDDataEntities db = new YDDataEntities())
                {
                    List<T_Permission> perlist = db.T_Permission.AsQueryable().ToList();

                    var roperlist = db.T_Role_Permission.Where(o=>o.Role_ID== roleID).AsQueryable();
                    foreach(var roper in roperlist) 
                    {
                        T_Permission per = perlist.Where(o => o.ID == roper.Permission_ID).FirstOrDefault();
                        if(per!=null)
                        {
                            per.IsChecked = true;
                        }
                    } 

                    return perlist;
                }
            }
            catch (Exception ex)
            {
                Errors.Add(ex);
                WriteException(ex);
                return null;
            }
        }

        
    }
}
